/*
 * Copyright (c) 2017 zhangcm. All Rights Reserved.
 */
package com.jnzc.ocr.common.utils;

import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;

/**
 * @author zhangcm
 * @version 1.0, 2017/10/6
 */
public class StringSubUtils {

    private StringSubUtils(){}

    public static String get(String s, Integer maxLen){
        return get(s, maxLen, "");
    }

    public static String get(String s, Integer maxLen, String omit){
        Preconditions.checkNotNull(maxLen);
        Preconditions.checkNotNull(omit);
        if(StringUtils.isEmpty(s)){
            return "";
        }
        if(s.length() <= maxLen){
            return s;
        }
        return s.substring(0, maxLen - omit.length()) + omit;
    }
}
